package org.zfes.snowier.zbss.xzy.router.solution;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.solution.model.AlgorithmConfigItem;
import org.zfes.snowier.zbss.xzy.biz.solution.service.IAlgorithmConfigItemService;
import org.zfes.snowier.core.data.SelectVo;
import org.zfes.snowier.core.util.ZAlert;
@Controller 
@RequestMapping("/manager/algorithm/config")
public class AlgorithmConfigController implements BaseController {

	
	@Autowired
	private IAlgorithmConfigItemService algorithmConfigItemService;
	
	  @RequestMapping(value="/loadConfigTreeGrid", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	  public @ResponseBody  Object loadConfigTreeGrid(Long algorithmId){
		  List<AlgorithmConfigItem>  treeGrid=  algorithmConfigItemService.loadByAlgorithmId(algorithmId, Byte.valueOf("1"));
		  return ajaxQuery("treeGrid", treeGrid);
	  }
	  
	
    @RequestMapping(value="/createAlgorithmConfigItem", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object createAlgorithmConfigItem(@RequestBody AlgorithmConfigItem algorithmConfigItem){
		algorithmConfigItemService.createAlgorithmConfigItem(algorithmConfigItem);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadAlgorithmConfigItem/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmConfigItem(@PathVariable("id")Long id){
		Optional<AlgorithmConfigItem> ops = algorithmConfigItemService.loadAlgorithmConfigItemById(id);
		return ajaxQuery("algorithmConfigItem",ops);
    }
	
    @RequestMapping(value="/updateAlgorithmConfigItem", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object updateAlgorithmConfigItem(@RequestBody  AlgorithmConfigItem algorithmConfigItem){
		algorithmConfigItemService.updateAlgorithmConfigItem(algorithmConfigItem);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/setAlgorithmConfigItemStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object setAlgorithmConfigItemStatus(Long id,Byte status){
    	AlgorithmConfigItem item = algorithmConfigItemService.loadAlgorithmConfigItemById( id).orElseThrow(()->ZAlert.newSLE("未查询到数据"));
		algorithmConfigItemService.setStatusByTreeCode(item.getTreeCode(), status);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
}